/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.gbvbahia.vendas.beans;

import br.com.gbvbahia.vendas.controllers.util.StringBeanUtils;
import br.com.gbvbahia.vendas.modelos.Telefone;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author guilherme
 */
@Stateless
public class TelefoneFacade extends AbstractFacade<Telefone> {

    @PersistenceContext(unitName = "VendasPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public TelefoneFacade() {
        super(Telefone.class);
    }

    public List<String> telefoneAutoComplete(final String telefone, final int maxResult) {
        Query q = getEntityManager().createNamedQuery("Telefone.autoCompleteMatricula");
        q.setParameter("telefone", StringBeanUtils.acertaNomeParaLike(
                telefone, StringBeanUtils.LIKE_END));
        q.setMaxResults(maxResult);
        return q.getResultList();
    }
}
